﻿/**
 * 功能:麦格纳斯[地狱] 事件
 * From:芬芬时尚潮流
 */
var mobid;
var mob;
var stats;
var modified;
var MaxRandom;
var setupTask;
var ostats;
var victor;

var mapID = 401060100;
var DPS = 15000;
var EXP = 500000;

//事件复活次数
var reviveCount = 5;

//死亡之后或者时间到了之后回去的地图
var BackMap = 401060000;

var dropItems = new Array(
		//=============================== 暴君系列 =========================================

		new Array(8880000, 1102481, 1, 1, 1), //暴君西亚戴斯披风
		new Array(8880000, 1102482, 1, 1, 1), //暴君赫尔梅斯披风
		new Array(8880000, 1102483, 1, 1, 1), //暴君凯伦披风
		new Array(8880000, 1102484, 1, 1, 1), //暴君利卡昂披风
		new Array(8880000, 1102485, 1, 1, 1), //暴君阿尔泰披风

		new Array(8880000, 1082543, 1, 1, 1), //暴君西亚戴斯手套
		new Array(8880000, 1082544, 1, 1, 1), //暴君赫尔梅斯手套
		new Array(8880000, 1082545, 1, 1, 1), //暴君凯伦手套
		new Array(8880000, 1082546, 1, 1, 1), //暴君利卡昂手套
		new Array(8880000, 1082547, 1, 1, 1), //暴君阿尔泰手套

		new Array(8880000, 1072743, 1, 1, 1), //暴君西亚戴斯靴
		new Array(8880000, 1072744, 1, 1, 1), //暴君赫尔梅斯靴
		new Array(8880000, 1072745, 1, 1, 1), //暴君凯伦靴
		new Array(8880000, 1072746, 1, 1, 1), //暴君利卡昂靴
		new Array(8880000, 1072747, 1, 1, 1), //暴君阿尔泰靴

		new Array(8880000, 1132174, 1, 1, 1), //暴君西亚戴斯腰带
		new Array(8880000, 1132175, 1, 1, 1), //暴君赫尔梅斯腰带
		new Array(8880000, 1132176, 1, 1, 1), //暴君凯伦腰带
		new Array(8880000, 1132177, 1, 1, 1), //暴君利卡昂腰带
		new Array(8880000, 1132178, 1, 1, 1), //暴君阿尔泰腰带
		//===================================================================================

		new Array(8880000, 2430144, 39, 1, 1), //秘密能手册
		new Array(8880000, 2430144, 39, 1, 1), //秘密能手册
		new Array(8880000, 4310143, 100, 1, 1), //BOSS币
		new Array(8880000, 2614003, 30, 1, 1), //突破10W之石
		new Array(8880000, 5390031, 70, 1, 1), //情景喇叭
		new Array(8880000, 5062000, 70, 1, 1), //一般神奇魔方
		new Array(8880000, 5062002, 35, 1, 1), //高级神奇魔方
		new Array(8880000, 5062009, 20, 1, 1), //超级神奇魔方
		new Array(8880000, 5062010, 14, 1, 1), //终极神奇魔方
		new Array(8880000, 5062001, 14, 1, 1), //混沌神奇魔方
		new Array(8880000, 5062500, 20, 1, 1), //大师附加魔方
		new Array(8880000, 2049137, 22, 1, 1), //惊人正义混沌卷轴 40%
		new Array(8880000, 5150040, 8, 1, 1), //皇家理发卷
		new Array(8880000, 5152053, 8, 1, 1) //皇家整容圈
		//怪物ID，物品ID，爆率，最小值，最大值
	);

function init() {
	em.setProperty("state", "0");
	em.setProperty("sum", "0");
}

function monsterDrop(eim, player, mob) {
	var mobid = mob.getId();
	var toDrop = new Array();
	for (var i = 0; i < dropItems.length; i++) {
		if (mobid != dropItems[i][0])
			continue;
		var chance = Math.floor(Math.random() * 220);
		if (chance < dropItems[i][2]) {
			var minQuantity = dropItems[i][3];
			var maxQuantity = dropItems[i][4];
			var quantity = Math.floor(Math.random() * (maxQuantity - minQuantity + 1) + minQuantity);
			toDrop.push(new Array(dropItems[i][1], quantity)); //载入暴率数组
		}
	}
	for (var i = 0; i < toDrop.length; i++) {
		if (player.getMap() != null)
			player.getMap().spawnMobDrop(em.newItem(toDrop[i][0], 0, toDrop[i][1]), new java.awt.Point(mob.getTruePosition().getX() + 25 * i, mob.getTruePosition().getY()), mob, player, 2, 0);
	}
}
function setup(level, leaderid) {
	var eim = em.newInstance("Boss_Mgns_4");
	var map = eim.setInstanceMap(mapID);
	map.resetPQ(level);
	map.resetFully();
	map.killAllMonsters(true);
	map.respawn(false);
	eim.startEventTimer(1000 * 60 * 40);
	mobid = 8880000; //麦格纳斯
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(500000000000); //20E
	modified.setOMp(mob.getMobMaxMp() * 30);
	modified.setOExp(EXP);
	mob.getStats().setPhysicalAttack(DPS); //物理伤害
	mob.getStats().setMagicAttack(DPS); //魔攻伤害
	mob.getStats().setAcc(500000);
	mob.getStats().setPDRate(100);
	mob.getStats().setMDRate(100);
	mob.getStats().setSpeed(600);
	mob.getStats().setLevel(220);
	mob.getStats().setAcc(500000);
	mob.setOverrideStats(modified);
	mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(mapID);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(2455, -1347));
	eim.setProperty("HPstate", "1");
	eim.schedule("checkChrHP", 1000 * 2);
	eim.schedule("summonFall", 1000 * 5);
	em.setProperty("state", "1");
	em.setProperty("sum", "1");
	return eim;

}
function playerEntry(eim, player) {
	var map = eim.getMapInstance(0);
	player.dropMessage(6, "[暴君王座副本] 进入到了挑战地图，请小心行事。");
	player.setReviveCount(reviveCount);
	player.changeMap(map, map.getPortal(0));
}

function scheduledTimeout(eim) {
	eim.disposeIfPlayerBelow(100, BackMap);
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
	em.setProperty("sum", "0");
}

function cancelSchedule() {}

function playerDead(eim, player) {}

function playerRevive(eim, player) {
	if (player.getReviveCount() > 0) {
		var map = player.getMap();
		player.eventRevive(); //扣除复活次数
		player.changeMap(map, map.getPortal(0));
		player.dropMessage(-1, "此副本可提供原地复活" + reviveCount + "次.你目前已经使用了" + (reviveCount - player.getReviveCount()) + "次.还有" + player.getReviveCount() + "次可用");
		return true;
	}
	player.addHP(50);
	var map = eim.getMapFactoryMap(BackMap);
	player.changeMap(map, map.getPortal(0));
	return true;
}

function changedMap(eim, player, mapid) { //如果地图状态改变，那么
	switch (mapid) { //实例化地图，不添加也会改变地图，但副本时间会消失。
	case 401060100: //暴君王座
		var map = eim.getMapInstance(mapID);
		map.startMapEffect("擅闯本王的城堡，你们这是在作死！！！", 5120125);
		break;
	default:
		player.dropMessage(-1, "已经退出本次副本");
		eim.unregisterPlayer(player);
		if (eim.disposeIfPlayerBelow(0, 0)) {
			player.restReviveCount();
			em.setProperty("state", "0");
			em.setProperty("leader", "true");
			em.setProperty("sum", "0");
		}
		break;
	}
}

function playerExit(eim, player) {
	eim.unregisterPlayer(player);
	if (eim.disposeIfPlayerBelow(0, 0)) {
		player.restReviveCount();
		em.setProperty("state", "0");
		em.setProperty("leader", "true");
		em.setProperty("sum", "0");
	}
}

function playerDisconnected(eim, player) {
	return 0;
}

function monsterValue(eim, mobid) { //如果怪物状态改变，那么
	/*if (mobid == 8880000) {
		em.setProperty("sum", "0");
		eim.broadcastPlayerMsg(-1, "系统正在计算此次挑战的奖励品.将在5秒之后出结果.");
		eim.schedule("reward", 1000 * 5);
	}*/
	return 1;
}

function monsterKilled(eim, player, cp) {}

function allMonstersDead(eim) {}

function monsterDamaged(eim, player, mobid, damage) {}

function leftParty(eim, player) {}
function disbandParty(eim) {}
function onMapLoad(eim, player) {}
/**
 * 召唤落下的球
 */
function summonFall(eim) {
	if (em.getProperty("sum") == 1) {
		var map = eim.getMapInstance(0);
		map.obtacleFall(5, 1, 8);
		eim.schedule("summonFall", 4000);
	}
}

function checkChrHP(eim) {
	var state = parseInt(eim.getProperty("HPstate"));
	if (state > 0) {
		var map = eim.getMapInstance(0);
		var mob = map.getMonsterById(8880000);
		if (mob != null) {
			for (i = 0; i < eim.getPlayers().size(); i++) {
				mob.checkMobZone(eim.getPlayers().get(i), true);
			}
			eim.schedule("checkChrHP", 2000);
		}
	}
}

function reward(eim, player) {
	var time = 30;
	//副本奖励
	openNpc(eim, 0, "副本奖励");
	//副本分级
	eim.setProperty("FBlv", "90");
	//难度等级
	eim.setProperty("FBnd", "4");
	//评分系统
	openNpc(eim, 0, "评价系统"); // - 评分系统

	eim.broadcastPlayerMsg(-1, "[" + time + "]秒之后.将回去原来的地方.尽情享受胜利的果实吧");
	eim.startEventTimer(1000 * time);
}

function openNpc(eim, npcid, mode) {
	for (var i = 0; i < eim.getPlayerCount(); i++) {
		eim.getPlayers().get(i).openNpc(npcid, mode);
	}
}
function pickUpItem(eim, player, itemID) {}
